package org.example.classloader.ASM;

import jdk.internal.org.objectweb.asm.ClassVisitor;
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;

import java.util.Set;

public class ModifyClassVisitor extends ClassVisitor {

    private Set<String> tranMehodSet;

    public ModifyClassVisitor(ClassVisitor classVisitor, Set<String> tranMehodSet) {

        super(Opcodes.ASM5, classVisitor);
        this.tranMehodSet = tranMehodSet;
    }

    public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {

        if (tranMehodSet.contains(name)) {
            MethodVisitor methodVisitor = super.visitMethod(access, name, desc, signature, exceptions);
            return new ModifyMethodVisitor(methodVisitor);
        }

        return super.visitMethod(access, name, desc, signature, exceptions);
    }
}